package com.time.workshop.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.time.workshop.App;
import com.time.workshop.R;
import com.time.workshop.SuperActivity;
import com.time.workshop.adapter.AddressAdapter;
import com.time.workshop.bean.CountyList;
import com.time.workshop.injector.Injector;
import com.time.workshop.injector.V;
/*
 * 街道
 */
public class AddressStreetActivity extends SuperActivity implements OnClickListener{
	private ListView xlistView;
	@V
	private TextView addrTextView;
	@V
	private ImageView img_login_back;

	private String county_name;

	private List<CountyList> streetList = new ArrayList<CountyList>();//街道
	private AddressAdapter madapter;

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.activity_addr_country);

		county_name = getIntent().getExtras().getString("county_name");
		//streetList = (List<CountyList>)getIntent().getSerializableExtra("streetList");

		CountyList street = new CountyList();
		street.setNAME("全部");
		streetList.add(street);
		streetList.addAll((List<CountyList>)getIntent().getSerializableExtra("streetList"));

		init();
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_login_back:
			back();
			break;
		default:
			break;
		}
	}	
	private void init() {
		Injector.getInstance().inject(this);
		img_login_back.setOnClickListener(this);
		addrTextView.setText(getResources().getString(R.string.city_name)+county_name);

		xlistView = (ListView) findViewById(R.id.xlistView);

		madapter = new AddressAdapter(this,streetList);
		xlistView.setAdapter(madapter);
		xlistView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if (!streetList.get(position).getNAME().equals("全部")) {
					App.street_name = streetList.get(position).getNAME();
					App.street_id = streetList.get(position).getID();
				}
				AddressCountyActivity.addrCountyActivity.finish();
				back();
			}
		});

	}
}
